package com.starlink.controller.admin;

import com.github.pagehelper.PageInfo;
import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.starlink.model.request.MallRefundsRequest;
import com.starlink.model.request.mall.AdminMallLogisticsRequest;
import com.starlink.model.request.mall.AdminRefundRequest;
import com.starlink.model.request.mall.WechatRefund;
import com.starlink.model.vo.book.MallArticlesBuyVO;
import com.starlink.model.vo.mall.AdminRefundsVO;
import com.starlink.service.MallRefundsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.starlink.common.enums.OperationTypeEnum.ADMIN_DAI_FA_HUO_PRICE;
import static com.starlink.common.enums.OperationTypeEnum.ADMIN_REFUND_PRICE;

/**
 * @Auther: zhouyuhang01
 * @Date: 2024/4/9 14:00
 * @Description: WechatBookOrderController
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/admin/refunds")
@Api(value = "【管理端】商城售后模块", tags = {"【管理端】商城售后模块"})
public class AdminRefundsController {

    @Autowired
    private MallRefundsService refundsService;

    @WebAccess(login = true)
    @ApiOperation("售后列表分页查询")
    @PostMapping("/pageList")
    public WebResponse<PageInfo<List<AdminRefundsVO>>> pageList(@SortDefault(sort = {"t1.create_time"}, direction = Sort.Direction.DESC) Pageable pageable,
                                                                @RequestBody AdminRefundRequest request) {
        return WebResponse.build(refundsService.pageList(request,pageable));
    }

    @WebAccess(login = true)
    @ApiOperation("审批")
    @PostMapping("/approval")
    public WebResponse<Boolean> approval(@RequestBody AdminRefundRequest request) {
        return WebResponse.build(refundsService.approval(request));
    }

    @WebAccess(login = true)
    @ApiOperation("收货")
    @PostMapping("/pass")
    public WebResponse<Boolean> pass(@RequestBody AdminRefundRequest request) {
        WechatRefund wechatRefund = new WechatRefund();
        wechatRefund.setOperationType(ADMIN_REFUND_PRICE.getType());
        return WebResponse.build(refundsService.pass(request,wechatRefund));
    }

    @WebAccess(login = true)
    @ApiOperation("换货发货")
    @PostMapping("/deliverChangeGoods")
    public WebResponse<Boolean> deliverChangeGoods(@RequestBody AdminMallLogisticsRequest request) {
        return WebResponse.build(refundsService.deliverChangeGoods(request));
    }

}
